package com.zsinfo.guoss.supplier.activity;

import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.netcenter.Event.Response;
import com.example.netcenter.RetrofitBuilder;
import com.example.netcenter.Url.ConstantsCode;
import com.example.netcenter.bean.QDetailBean;
import com.example.netcenter.bean.ResultsData;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zsinfo.guoss.supplier.R;
import com.zsinfo.guoss.supplier.base.BaseActivity;

import java.util.List;

import butterknife.BindView;

/**
 * 报价详情
 */
public class FruitOfferDetailActivity extends BaseActivity {


    @BindView(R.id.iv_shop_logo)
    ImageView iv_shop_logo;
    @BindView(R.id.fruit_name)
    TextView fruit_name;
    @BindView(R.id.tv_fruit_offer)
    TextView tv_fruit_offer;
    @BindView(R.id.tv_fruit_mark)
    TextView tv_fruit_mark;
    @BindView(R.id.tv_create_time)
    TextView tv_create_time;
    @BindView(R.id.tv_status)
    TextView tv_status;
    @BindView(R.id.tv_fruit_require)
    TextView tv_fruit_require;
    @BindView(R.id.tv_fruit_specification)
    TextView tv_fruit_specification;
    @BindView(R.id.account_container)
    RecyclerView account_container;

    @Override
    protected int getContentLayoutRes() {
        return R.layout.activity_fruit_detail;
    }

    @Override
    protected void initView() {
        setTitle("报价详情");
        setBackAndLeftTitle("")
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
    }

    @Override
    protected void initNetData() {

        requestData();


    }


    private void requestData() {
        GetNetCenter().GetNetCenter(this,
                RetrofitBuilder.CreateApi().QUOTED_DETAILS(ConstantsCode.quoted_details, getIntent().getStringExtra("quotedId")), new Response() {
                    @Override
                    public void OK(Object data) {
                        ResultsData<QDetailBean> product = (ResultsData<QDetailBean>) data;

                        Glide.with(FruitOfferDetailActivity.this).load(product.getData().getGoods().getLogo()).into(iv_shop_logo);


                        tv_create_time.setText(product.getData().getGoods().getCreateTime());


                        if (product.getData().getQuotedRcd().getStatus() == 1) {
                            tv_status.setText("竞价成功");
                            tv_status.setTextColor(Color.GREEN);
                        } else if (product.getData().getQuotedRcd().getStatus() == -1) {
                            tv_status.setText("竞价失败");
                            tv_status.setTextColor(Color.GRAY);
                        } else {
                            tv_status.setText("竞价中");
                            tv_status.setTextColor(Color.RED);
                        }

                        tv_fruit_offer.setText(product.getData().getQuotedRcd().getPrice() + "元/斤");

                        tv_fruit_mark.setText(product.getData().getQuotedRcd().getNote());

                        fruit_name.setText(product.getData().getGoods().getName());

                        tv_fruit_require.setText(product.getData().getGoods().getSourceCity());

                        tv_fruit_specification.setText(product.getData().getGoods().getSizeDesc());

                        if (product.getData().getGoods().getProps().size() > 0) {

                            DynamicLayout(product.getData().getGoods().getProps());

                        }


                    }

                    @Override
                    public void Fail(Throwable e) {
                        Log.e("lixl", e.getMessage());
                    }

                    @Override
                    public void complete() {

                    }
                });

    }

    @Override
    protected void customDestroy() {

    }

    void DynamicLayout(List<QDetailBean.GoodsBean.PropsBean> props) {

        CommonAdapter myAdapter = new CommonAdapter<QDetailBean.GoodsBean.PropsBean>(this, R.layout.item_free_line, props) {
            @Override
            protected void convert(final ViewHolder holder, QDetailBean.GoodsBean.PropsBean s, int position) {

                holder.setText(R.id.tv_key, s.getKey()).setText(R.id.tv_value, s.getValue());

            }
        };
        account_container.setAdapter(myAdapter);
        account_container.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    }

}
